package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.Strategycatalog;
import cn.wolfcode.trip.base.query.StrategyQueryObject;
import cn.wolfcode.trip.base.query.StrategycatalogQueryObject;
import cn.wolfcode.trip.base.service.IStrategyService;
import cn.wolfcode.trip.base.service.IStrategycatalogService;
import cn.wolfcode.trip.base.util.JasonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/strategyCatalog")
public class StrategycatalogController {

    @Autowired
    private IStrategycatalogService strategycatalogService;
    @Autowired
    private IStrategyService strategyService ;


    /**
     * 根据大攻略的id，查出所对应的攻略分类
     */
    @RequestMapping("/queryCatalogBystrategyId.do")
    @ResponseBody
    public Object queryCatalogBystrategyId(Long strategyId){
        return strategycatalogService.queryCatalogBystrategyId(strategyId);
    }



    /**
     * 攻略分类的主页面
     * @param qo
     * @param model
     * @return
     */
    @RequestMapping("/list.do")
    public String list(@ModelAttribute("qo") StrategycatalogQueryObject qo, Model model){
        model.addAttribute("pageInfo",strategycatalogService.query(qo));
        //查询所有没有被禁用的大攻略
        model.addAttribute("strategys",strategyService.listEnable());
        return "strategycatalog/list" ;
    }
    /*
        新增或修改攻略分类
     */
    @RequestMapping("/saveOrUpdate.do")
    @ResponseBody
    public Object saveOrUpdate(Strategycatalog strategycatalog){
        JasonResult jr = new JasonResult();
        try {
            strategycatalogService.saveOrUpdate(strategycatalog);
        } catch (Exception e) {
            e.printStackTrace();
            jr.mark(e.getMessage());
        }
        return jr;
    }

}
